﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ComponentModel;
using KerriganMobile.MobileServiceWCF;
using System.Collections.ObjectModel;
using KerriganMobile.Models;
using System.Diagnostics;

namespace KerriganMobile.Views
{
    public partial class SessionList : PhoneApplicationPage
    {
        private SessionListVO vo;

        public SessionList()
        {
            InitializeComponent();
            vo = new SessionListVO();
            DataContext = vo;
        }

        void  client_GetSessionsByCustomerWithoutMarkTodayCompleted(object sender, GetSessionsByCustomerWithoutMarkTodayCompletedEventArgs e)
        {
            this.vo.SessionList = e.Result;
        }

        private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SessionDC session = (sender as ListBox).SelectedItem as SessionDC;
            if (session != null)
            {
                ApplicationManager.ID_CURRENT_SESSION = session.Id;
                ApplicationManager.changeURI(this, "AddMark");
            }
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

            ApplicationManager.client.GetSessionsByCustomerWithoutMarkTodayCompleted += new EventHandler<GetSessionsByCustomerWithoutMarkTodayCompletedEventArgs>(client_GetSessionsByCustomerWithoutMarkTodayCompleted);
            ApplicationManager.client.GetSessionsByCustomerWithoutMarkTodayAsync(ApplicationManager.ID_CURRENT_CUSTOMER, ApplicationManager.ID_CURRENT_INSTRUCTOR);
            Debug.WriteLine("Loaded SessionList");
        }

    }




    public class SessionListVO : INotifyPropertyChanged
    {
        public SessionListVO()
        {
            SessionList = new ObservableCollection<SessionDC>();
        }

        private ObservableCollection<SessionDC> _sessionList;


        public ObservableCollection<SessionDC> SessionList
        {
            get
            {
                return this._sessionList;
            }
            set
            {
                this._sessionList = value;
                OnPropertyChanged("SessionList");
            }

        }


        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

    }

}